package edu.hawaii.senin.iclouds.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

import edu.hawaii.senin.iclouds.basics.Reaction;
import edu.hawaii.senin.iclouds.basics.ReactionFactory;

/**
 * Helper class to convert Original IDL implementation Reaction config into XML stuff.
 * 
 * @author Pavel Senin.
 * 
 */
public class ConvertIDLReaction {

  /**
   * Runs the converter.
   * 
   * @param args - input and output file should specified as the first and second arguments.
   */
  public static void main(String[] args) {

    String reactionsInIDL = args[0];
    String reactionsIClouds = args[1];

    ReactionFactory rf = new ReactionFactory();

    try {
      BufferedReader in = new BufferedReader(new FileReader(new File(reactionsInIDL)));
      BufferedWriter out = new BufferedWriter(new FileWriter(new File(reactionsIClouds)));
      ArrayList<Reaction> rs = rf.buildTheList(in);
      rf.dumpToFile(rs, out);
      in.close();
      out.close();
    }
    catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

}
